package com.pie4cloud.pie.job.biz.controller;


import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pie4cloud.pie.common.core.util.R;
import com.pie4cloud.pie.common.log.annotation.SysLog;
import com.pie4cloud.pie.job.api.entity.DmzEntity;
import com.pie4cloud.pie.job.biz.config.FeignRemote;
import com.pie4cloud.pie.job.biz.service.DmzService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/dmz" )
public class DmzController {
	@Autowired
	private DmzService dmzService;
	@Autowired
	private FeignRemote feignRemote;
	@Autowired
	private NacosServiceManager nacosServiceManager;
	@Autowired
	private NacosDiscoveryProperties nacosDiscoveryProperties;

/*
	public void registerNacos(){
		NamingService namingService=nacosServiceManager.getNamingService(nacosDiscoveryProperties.getNacosProperties());
		try {
			namingService.registerInstance("pie-dmz","127.0.0.1",8858);
		} catch (NacosException e) {
			e.printStackTrace();
		}
	}
*/

	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page" )
	public R getTDataJobInfoPage(Page page, DmzEntity dmzEntity) {
		return R.ok(dmzService.page(page,dmzEntity));
	}

	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
	public R getById(@PathVariable("id" ) Long id) {
		return R.ok(dmzService.getById(id));
	}


	@ApiOperation(value = "新增", notes = "新增")
	@SysLog("新增" )
	@PostMapping
	public R save(@RequestBody DmzEntity dmzEntity) {
		return R.ok(dmzService.save(dmzEntity));
	}

	@ApiOperation(value = "修改", notes = "修改")
	@SysLog("修改" )
	@PutMapping
	public R updateById(@RequestBody DmzEntity dmzEntity) {
		return R.ok(dmzService.update(dmzEntity));
	}

	@ApiOperation(value = "通过id删除", notes = "通过id删除")
	@SysLog("通过id删除" )
	@DeleteMapping("/{id}" )
	public R removeById(@PathVariable Long id) {
		dmzService.removeById(id);
		return R.ok();
	}

}
